package com.example.unveil_the_leader.controller;

import com.example.unveil_the_leader.common.Result;
import com.example.unveil_the_leader.entity.Users;
import com.example.unveil_the_leader.service.UsersService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@CrossOrigin
@Api(tags = "用户管理接口")
@RestController
@RequestMapping("/users")
public class UsersController {

    @Autowired
    private UsersService usersService;

    //登录
    @PostMapping("/login")
    public Result login_U(@RequestParam("username") String username,
                          @RequestParam("password") String password){
        return usersService.login(username, password);
    }

    //获取验证码
    @PostMapping("/getCode")
    public Result getCheckCode(@RequestParam("qq") String qq,
                               HttpServletRequest request){
        return usersService.getCode(qq, request);
    }

    //注册
    @PostMapping("/register")
    public Result register_U(@RequestParam("username") String username,
                             @RequestParam("password") String password,
                             @RequestParam("qq") String qq,
                             @RequestParam("code") String code,
                             HttpServletRequest request){
        return usersService.register(username, password, qq,code,request);
    }

    //修改个人信息
    @PutMapping("/update")
    public Result update_U(@RequestBody Users users){
        return  usersService.updateMsg(users);
    }

}
